﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlTypes;
using System.Data.SqlClient;
using System.Data;

namespace FreeProperty.Data
{
    public class State : NameValue
    {
        public SqlInt32 StateID { get; set; }
        public string StateName { get; set; }
        public List<State> LoadAll()
        {
            SqlCommand cmd = GetSPCommand("getStates");
            SqlDataReader reader = cmd.ExecuteReader(CommandBehavior.CloseConnection);
            List<State> lstState = new List<State>();
            while (reader.Read())
            {
                State oState = new State();
                oState.StateID = ToSqlInt32(reader["StateID"]);
                oState.StateName = ToString(reader["StateName"]);
                lstState.Add(oState);
            }
            reader.Close();
            reader = null;
            return lstState;
        }
    }

    public class District : NameValue
    {
        public SqlInt32 DistrictID { get; set; }
        public string DistrictName { get; set; }
        public List<District> LoadAll(int StateID)
        {
            SqlCommand cmd = GetSPCommand("getDistricts");
            cmd.Parameters.Add(new SqlParameter("@prmStateID", StateID));
            SqlDataReader reader = cmd.ExecuteReader(CommandBehavior.CloseConnection);
            List<District> lstDistrict = new List<District>();
            while (reader.Read())
            {
                District oDistrict = new District();
                oDistrict.DistrictID = ToSqlInt32(reader["DistrictID"]);
                oDistrict.DistrictName = ToString(reader["DistrictName"]);
                lstDistrict.Add(oDistrict);
            }
            reader.Close();
            reader = null;
            return lstDistrict;
        }
        public List<NameValue> LoadAllNameValue(int StateID)
        {
            SqlCommand cmd = GetSPCommand("getDistricts");
            cmd.Parameters.Add(new SqlParameter("@prmStateID", StateID));
            SqlDataReader reader = cmd.ExecuteReader(CommandBehavior.CloseConnection);
            List<NameValue> lstNameValue = new List<NameValue>();
            while (reader.Read())
            {
                NameValue oNameValue = new NameValue();
                oNameValue.Value = ToSqlInt32(reader["DistrictID"]).ToString();
                oNameValue.Name = ToString(reader["DistrictName"]);
                lstNameValue.Add(oNameValue);
            }
            reader.Close();
            reader = null;
            return lstNameValue;
        }

    }
    
}
